﻿<Window x:Class="remes.BLoc.UI.TranslationEditor"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:remes.BLoc.UI"
        xmlns:bloc="clr-namespace:remes.BLoc;assembly=BLocCore"
        Title="Baml Localizer - Translation editor" Height="800" Width="1000"
        Loaded="Window_Loaded">

  <Window.CommandBindings>
    <CommandBinding Command="Save" CanExecute="SaveCommand_CanExecute" Executed="SaveCommand_Executed"/>
  </Window.CommandBindings>

  <Window.Resources>
    <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="TranslationTextStateEnum">
      <ObjectDataProvider.MethodParameters>
        <x:Type TypeName="bloc:TranslationTextState"/>
      </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>

    <CollectionViewSource x:Key="EntriesView"
                          Source="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=TranslationSet.Entries.Values}"
                          Filter="CollectionViewSource_Filter">
    </CollectionViewSource>

    <DataTemplate x:Key="TextEditorTemplate">
      <TextBox Text="{Binding Path=SelectedText.Text}"/>
    </DataTemplate>

    <DataTemplate x:Key="TranslatorsCommentEditorTemplate">
      <TextBox Text="{Binding Path=SelectedText.TranslatorsComment}"/>
    </DataTemplate>

    <DataTemplate x:Key="TextStateEditorTemplate">
      <ComboBox ItemsSource="{Binding Source={StaticResource TranslationTextStateEnum}}" SelectedItem="{Binding Path=SelectedText.State}"/>
    </DataTemplate>
  </Window.Resources>

  <DockPanel>
    <ToolBarTray DockPanel.Dock="Top">
      <ToolBar Band="0">
        <Button Content="Save" x:Name="SaveButton" Command="Save"/>
      </ToolBar>
    </ToolBarTray>

    <Expander DockPanel.Dock="Top" ExpandDirection="Down" IsExpanded="True" Header="View settings" x:Name="ViewSettingsExpander">
      <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
        <StackPanel Orientation="Horizontal" MaxHeight="100">
          <StackPanel.Resources>
            <Style TargetType="{x:Type Border}">
              <Setter Property="BorderBrush" Value="Blue"/>
              <Setter Property="BorderThickness" Value="1"/>
              <Setter Property="Margin" Value="1"/>
              <Setter Property="Padding" Value="2"/>
              <Setter Property="CornerRadius" Value="5"/>
            </Style>
          </StackPanel.Resources>

          <Border>
            <Expander ExpandDirection="Right" IsExpanded="True">
              <Expander.Header>
                <TextBlock Text="Grouping">
                  <TextBlock.LayoutTransform>
                    <RotateTransform Angle="-90"/>
                  </TextBlock.LayoutTransform>
                </TextBlock>
              </Expander.Header>

              <ItemsControl Margin="3" x:Name="GroupingsList"
                            ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=Columns}">
                <ItemsControl.Resources>
                  <DataTemplate DataType="{x:Type local:GridColumn}">
                    <CheckBox Content="{Binding Path=Header}" IsChecked="{Binding Path=GroupBy, Mode=TwoWay}" Checked="GroupingCheckBox_Changed" Unchecked="GroupingCheckBox_Changed"/>
                  </DataTemplate>
                </ItemsControl.Resources>
              </ItemsControl>
            </Expander>
          </Border>

          <Border>
            <Expander ExpandDirection="Right" IsExpanded="True">
              <Expander.Header>
                <TextBlock Text="Filter">
                  <TextBlock.LayoutTransform>
                    <RotateTransform Angle="-90"/>
                  </TextBlock.LayoutTransform>
                </TextBlock>
              </Expander.Header>

              <WrapPanel Orientation="Vertical" Margin="0,3">
                <CheckBox Content="Deleted" IsThreeState="True" IsChecked="False" Margin="3,0" x:Name="FilterDeletedCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="Readable" IsThreeState="True" IsChecked="True" Margin="3,0" x:Name="FilterReadableCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="Modifiable" IsThreeState="True" IsChecked="True" Margin="3,0" x:Name="FilterModifiableCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="Empty Text" IsThreeState="True" IsChecked="False" Margin="3,0" x:Name="FilterEmptyTextCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="Number Text" IsThreeState="True" IsChecked="False" Margin="3,0" x:Name="FilterNumberTextCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="State: New" IsThreeState="False" IsChecked="True" Margin="3,0" x:Name="FilterStateNewTextCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="State: Orig. text changed" IsThreeState="False" IsChecked="True" Margin="3,0" x:Name="FilterStateOrigTextChangedTextCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="State: Auto translated" IsThreeState="False" IsChecked="True" Margin="3,0" x:Name="FilterStateAutoTranslatedTextCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="State: Translated" IsThreeState="False" IsChecked="False" Margin="3,0" x:Name="FilterStateTranslatedTextCheckbox" Click="FilterCheckbox_Click"/>
                <CheckBox Content="State: No trans. needed" IsThreeState="False" IsChecked="False" Margin="3,0" x:Name="FilterStateNoTranslationNeededTextCheckbox" Click="FilterCheckbox_Click"/>
                <StackPanel Orientation="Vertical">
                  <Button Content="Show all" Margin="3,1" Padding="2,1" MinWidth="75" x:Name="FilterShowAllButton" Click="FilterShowAllButton_Click"/>
                  <Button Content="Show default" Margin="3,1" Padding="2,1" MinWidth="75" x:Name="FilterShowDefaultButton" Click="FilterShowDefaultButton_Click"/>
                </StackPanel>
              </WrapPanel>
            </Expander>
          </Border>

          <Border>
            <Expander ExpandDirection="Right" IsExpanded="True">
              <Expander.Header>
                <TextBlock Text="Misc">
                  <TextBlock.LayoutTransform>
                    <RotateTransform Angle="-90"/>
                  </TextBlock.LayoutTransform>
                </TextBlock>
              </Expander.Header>

              <StackPanel Orientation="Vertical" Margin="3">
                <StackPanel Orientation="Horizontal">
                  <TextBlock Text="Language " VerticalAlignment="Center"/>
                  <ComboBox MinWidth="60" Margin="3,0" x:Name="TargetLanguageComboBox" SelectionChanged="TargetLanguageComboBox_SelectionChanged"
                            SelectedItem="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=TranslationSet.SelectedLang}"
                            ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}, Path=TranslationSet.TargetLanguages}"/>
                  <Button Content="+" x:Name="AddTargetLanguageButton" Margin="3,0" Padding="2,1" MinWidth="20" Click="AddTargetLanguageButton_Click"/>
                  <Button Content="-" x:Name="RemoveTargetLanguageButton" Margin="3,0" Padding="2,1" MinWidth="20" Click="RemoveTargetLanguageButton_Click"/>
                </StackPanel>
              </StackPanel>
            </Expander>
          </Border>
        </StackPanel>
      </ScrollViewer>
    </Expander>

    <Expander DockPanel.Dock="Top" ExpandDirection="Down" IsExpanded="True" Header="Selected entry" x:Name="SelectedEntryExpander"
              DataContext="{Binding ElementName=EntriesList, Path=SelectedItem}">
      <Border BorderBrush="Blue" BorderThickness="1" CornerRadius="5" Margin="1" Padding="2">
        <StackPanel Orientation="Vertical">
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="Stream name:" Margin="5,1" VerticalAlignment="Center"/>
            <TextBlock Text="{Binding Path=StreamName}" Margin="0,1,10,1" VerticalAlignment="Center" FontWeight="Bold"/>

            <TextBlock Text="Key:" Margin="5,1" VerticalAlignment="Center"/>
            <TextBlock Text="{Binding Path=Key}" Margin="0,1,10,1" VerticalAlignment="Center" FontWeight="Bold"/>
          </StackPanel>
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="Orig. lang.:" Margin="5,1" VerticalAlignment="Center"/>
            <TextBlock Text="{Binding Path=OriginalLanguage}" Margin="0,1,10,1" VerticalAlignment="Center" FontWeight="Bold"/>

            <TextBlock Text="Readable:" Margin="5,1" VerticalAlignment="Center"/>
            <TextBlock Text="{Binding Path=IsReadable}" Margin="0,1,10,1" VerticalAlignment="Center" FontWeight="Bold"/>

            <TextBlock Text="Modifiable:" Margin="5,1" VerticalAlignment="Center"/>
            <TextBlock Text="{Binding Path=IsModifiable}" Margin="0,1,10,1" VerticalAlignment="Center" FontWeight="Bold"/>

            <TextBlock Text="State:" Margin="5,1" VerticalAlignment="Center"/>
            <ComboBox MinWidth="150" ItemsSource="{Binding Source={StaticResource TranslationTextStateEnum}}" SelectedItem="{Binding Path=SelectedText.State}"/>
          </StackPanel>
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="Comments:" Margin="5,1" VerticalAlignment="Center"/>
            <TextBlock Text="{Binding Path=Comments}" VerticalAlignment="Center" FontWeight="Bold"/>
          </StackPanel>
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="Auto"/>
              <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
              <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <TextBlock Grid.Column="0" Grid.Row="0" Text="Orig. text:" Margin="5,0" VerticalAlignment="Center"/>
            <TextBox Grid.Column="1" Grid.Row="0" Text="{Binding Path=OriginalText, Mode=OneWay}" IsReadOnly="True"/>

            <TextBlock Grid.Column="0" Grid.Row="1" Text="Text:" Margin="5,0" VerticalAlignment="Center"/>
            <TextBox Grid.Column="1" Grid.Row="1" Text="{Binding Path=SelectedText.Text}"/>

            <TextBlock Grid.Column="0" Grid.Row="2" Text="Comments:" Margin="5,0" VerticalAlignment="Center"/>
            <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Path=SelectedText.TranslatorsComment}"/>
          </Grid>
        </StackPanel>
      </Border>
    </Expander>

    <ListView ItemsSource="{Binding Source={StaticResource EntriesView}}" x:Name="EntriesList">
      <ListView.View>
        <GridView/>
      </ListView.View>

      <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
          <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
      </ListView.ItemContainerStyle>

      <ListView.GroupStyle>
        <GroupStyle>
          <GroupStyle.ContainerStyle>
            <Style TargetType="{x:Type GroupItem}">
              <Setter Property="Margin" Value="0,0,0,5"/>
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type GroupItem}">
                    <StackPanel Orientation="Vertical">
                      <Border BorderBrush="DarkGray" BorderThickness="0,1,0,1">
                        <Border.Background>
                          <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                            <GradientStop Offset="0" Color="White"/>
                            <GradientStop Offset="1" Color="LightGray"/>
                          </LinearGradientBrush>
                        </Border.Background>
                        <DockPanel Margin="0,2">
                          <TextBlock FontWeight="Bold" Text="{Binding Path=Name}" Margin="5,0,0,0"/>
                          <TextBlock Margin="5,0,0,0" Text="#"/>
                          <TextBlock FontWeight="Bold" Text="{Binding Path=ItemCount}"/>
                        </DockPanel>
                      </Border>
                      <ItemsPresenter />
                    </StackPanel>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
            </Style>
          </GroupStyle.ContainerStyle>
        </GroupStyle>
      </ListView.GroupStyle>

    </ListView>
  </DockPanel>
</Window>
